<?php
// +----------------------------------------------------------------------
// | XShop小程序商城
// +----------------------------------------------------------------------
// | Author: Peak Xin <xinyflove@gmail.com>
// +----------------------------------------------------------------------

namespace app\api\controller\v1;

use app\api\validate\IDCollection;
use app\api\model\Theme as ThemeModel;
use app\api\validate\IDMustBePositiveInt;
use app\lib\exception\ThemeException;
use think\Controller;

class Theme extends Controller {

    /**
     * @url /theme?ids=id1,id2,id3,....
     * @param string $ids
     * @return false|\PDOStatement|string|\think\Collection 一组theme模型
     * @throws ThemeException
     * @throws \app\lib\exception\ParameterException
     */
    public function getSimpleList($ids='')
    {
        (new IDCollection())->goCheck();
        $ids = explode(',', $ids);
        $result = ThemeModel::with('topicImg,headImg')->select($ids);
        if($result->isEmpty()) throw new ThemeException();
        return $result;
    }

    /**
     * @url /theme/:id
     * @param $id
     * @return string
     * @throws \app\lib\exception\ParameterException
     */
    public function getComplexOne($id)
    {
        (new IDMustBePositiveInt())->goCheck();
        $theme = ThemeModel::getThemeWithProducts($id);
        if(!$theme) throw new ThemeException();
        return $theme;
    }
}
